//
// Created by lingzhitech on 25-9-18.
//


#include <filesystem>
#include <fstream>
#include <iosfwd>
#include <iostream>

#include  "../material/QueryResult.h"
#include "../material/TextQuery.h"
int main() {
    std::ifstream infile("../ch12/text");
    if (!infile) {
        std::cout << std::filesystem::current_path() << std::endl;
        std::cerr << "cannot open file\n";
        return 1;
    }
    // infile is an ifstream that is the file we want to query
    TextQuery tq(infile); // store the file and build the query map
    // iterate with the user: prompt for a word to find and print results
    while (true) {
        std::cout << "enter word to look for, or q to quit: ";
        std::string s;
        // stop if we hit end-of-file on the input or if a 'q' is entered
        if (!(std::cin >> s) || s == "q") break;
        // run the query and print the results
        print(std::cout, tq.query(s)) << std::endl;
    }
}
